<template>
	<view class="container">
		<view class="content">
			<!-- 地址 搜索框 -->
			<view class="header-c">
				<view class="header-l">
					<i class="icon mt-location-o"></i>
					<span>北京市</span>
					<i class="icon mt-arrow-right-o"></i>
				</view>
				<view class="header-r">
					<i class="icon mt-search-o"></i>
					<span>请输入收货地址</span>
				</view>
			</view>
			<!-- 分类导航 金刚区 -->
			<swiper class="category-c" indicator-dots indicator-active-color="#F9D173">
				<!-- 金刚区 -->
				<view v-for="(item, index) in primary_filter" :key="index">
					<swiper-item>
						<view class="grid-c">
							<view class="item" v-for="eachItem in item.items" :key="eachItem.code" @click="toCategoryDetail(eachItem.code)">
								<img class="item-img" :src="eachItem.url" :alt="eachItem.name">
								<span class="item-title">{{eachItem.name}}</span>
							</view>
						</view>
					</swiper-item>
				</view>
			</swiper>
			<!-- 轮播图 -->
			<swiper class="ad-c" autoplay interval=3000>
				<swiper-item v-for="(item, index) in top_banner_list" :key="index">
					<img class="ad-img" :src="item.banner_pic_url">
				</swiper-item>
			</swiper>
			<!-- 附近商家 -->
			<view class="section">
				<view class="l"></view>
				<span class="m">附近商家</span>
				<view class="r"></view>
			</view>
			<view class="category-list">
				<!-- 条件排序 -->
				<view class="filter-bar">
					<view class="item" v-for="(item, index) in filterList" :key="index">
						<span>{{item.title}}</span>
						<i class="icon" :class="item.icon"></i>
					</view>
				</view>
				<!-- 商家列表部分 -->
				<view class="item-list">
					<!-- 满减优惠等标签 -->
					<view class="header">
						<view class="item" v-for="(item, index) in tags" :key="index">
							<span>{{item}}</span>
						</view>
					</view>
					<!-- 商家信息 -->
					<view class="item bottom-line" v-for="item in poilist" :key="item.id" @click="toShop(item.id)">
						<!-- 左 -->
						<view class="item-l">
							<img :src="item.pic_url" :alt="item.name">
							<!-- 活动标签 -->
							<img class="tag" :src="item.poi_promotion_pic" alt="狂欢月">
						</view>
						<!-- 右 -->
						<view class="item-r">
							<!--  -->
							<view class="r-t">
								<span class="shop-name">{{item.name}}</span>
								<view class="t-c">
									<view class="c-l">
										<view class="l-l">
											<!-- 星级 -->
											<i class="icon mt-star-s" v-for="(star, idx) in stars" :key="idx"></i>
										</view>
										<!-- 评价 -->
										<span class="l-m">{{item.wm_poi_score}}</span>
										<!-- 月售 -->
										<span class="l-r">{{item.month_sales_tip}}</span>
									</view>
									<!-- 时间距离 -->
									<view class="c-r">
										<span class="r-l">{{item.delivery_time_tip}}</span>
										<view class="r-m"></view>
										<span class="r-r">{{item.distance}}</span>
									</view>
								</view>
							</view>
							<!-- 各种价格 -->
							<view class="r-m">
								<span class="m-l">{{item.min_price_tip}}</span>
								<view class="m-m"></view>
								<span class="m-r">{{item.shipping_fee_tip}}</span>
								<view class="m-m"></view>
								<span class="m-r">{{item.average_price_tip}}</span>
							</view>
							<!-- 支持自取 急速配送 -->
							<view class="r-b">
								<span class="b-l">支持自取</span>
								<span class="b-r">极速配送</span>
							</view>
							<!-- 底部活动标签 -->
							<view class="activity-c">
								<view class="ac-item" v-for="(item, index) in item.discounts2" :key="index">
									<view class="ac">
										<img class="ac-l" :src="item.icon_url" alt="活动">
										<span class="ac-r">{{item.info}}</span>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapActions, mapState, mapGetters} from 'vuex'
	export default {
		// 数据
		data() {
			return {
				// 排序
				filterList: [
					{
						title: '综合排序',
						icon: 'mt-arrow-down-o'
					},
					{
						title: '销量最高'
					},
					{
						title: '速度最快'
					},
					{
						title: '筛选',
						icon: 'mt-filter-o'
					},
				],
				// 标签
				tags: ['满减优惠', '点评高分', '新商家', '美团专送'],
				// 星数
				stars: [1, 2, 3, 4, 5]
			}
		},
		computed: {
			...mapState({
				indexData: state => state.indexData.indexData
			}),
			...mapGetters(['primary_filter', 'top_banner_list', 'poilist'])
		},
		// 方法
		methods: {
			...mapActions(['getIndexData']),
			// 跳转到分类详情页
			toCategoryDetail(code) {
				uni.navigateTo({
					url: '/pages/categoryDetail/categoryDetail?code=' + `${code}`,
				})
			},
			// 跳转到商家订餐页
			toShop(id) {
				uni.navigateTo({
					url: `/pages/shop/shop?id=${id}`
				})
			}
		},
		mounted() {
			this.getIndexData()
		}
	}
</script>

<style lang="scss" scoped>
.container {
	background-color: #fff;
  .content {
    display: flex;
    flex-direction: column;
    position: relative;
    .header-c {
      display: flex;
      align-items: center;
      height: 80rpx;
      position: fixed;
      width: auto;
      padding: 0 30rpx;
      width: 100%;
      box-sizing: border-box;
      background-color: white;
      z-index: 999;
      .header-l {
        display: flex;
        align-items: center;
        span {
          font-size: 28rpx;
          color: #333;
          margin: 0 10rpx;
        }
      }
      .header-r {
        display: flex;
        align-items: center;
        flex: 1;
        background-color: #F4F4F4;
        height: 60rpx;;
        border-radius: 30rpx;
        margin-left: 30rpx;
        align-items: center;
        i {
          color: #666;
          font-size: 32rpx;
          margin-left: 20rpx;
        }
        span {
          color: #666;
          font-size: 24rpx;
          margin-left: 10rpx;
        }
      }
    }
    .category-c {
      height: 360rpx;
      background-color: white;
      padding-top: 100rpx;
      .grid-c {
        height: 340rpx;
        flex-wrap: wrap;
        display: flex;
        .item {
          width: 20%;
          background-color: white;
          display: flex;
          flex-direction: column;
          align-items: center;
          box-sizing: border-box;
          img {
            width: 80rpx;
            height: 80rpx;
            border-radius: 40rpx;
          }
          span {
            font-size: 20rpx;
            color: #333;
            margin-top: 10rpx;
          }
        }
      }
    }
    .ad-c {
      display: flex;
      height: 200rpx;
      background-color: white;
      margin: 20rpx;
      .ad-img {
        height: 200rpx;
        width: 100%;
        background-size: cover;
      }
    }
    .b-banner {
      display: flex;
      flex-direction: column;
      .recommended {
        display: flex;
        align-items: center;
        height: 160rpx;
        margin: 20rpx;
        margin-top: 0;
        img {
          height: 160rpx;
          width: 100%;
          background-size: cover;
        }
      }
      .hot-sale {
        display: flex;
        background-color: white;
        height: 160rpx;
        justify-content: space-between;
        margin: 0 20rpx;
        .item {
          display: flex;
          flex-direction: column;
          width: 160rpx;
          padding: 0 20rpx;
          height: 160;
          .img-c {
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            img {
              width: 160rpx;
              height: 120rpx;
              border-radius: 8rpx;
            }
            .name-c {
              display: flex;
              align-items: center;
              position: absolute;
              height: 30rpx;
              bottom: 0;
              background: rgba($color: #000000, $alpha: 0.3);
              width: 160rpx;
              .name {
                font-size: 20rpx;
                color: white;
                margin: 0 10rpx;
                height: 30rpx;
                overflow: hidden;
              }
            }
          }
          .price {
            font-size: 24rpx;
            color: #e74c3c;
            margin: 10rpx 0;
          }
        }
      }
    }
    .section {
      display: flex;
      align-items: center;
      margin: 20rpx;
      justify-content: center;
      box-sizing: border-box;
      .l {
        height: 2rpx;
        width: 60rpx;
        background-color: #666;
      }
      .m {
        font-size: 32rpx;
        color: #333;
        margin: 0 20rpx;
        font-weight: bold;
      }
      .r {
        height: 2rpx;
        width: 60rpx;
        background-color: #666;
      }
    }
    .category-list {
      display: flex;
      flex-direction: column;
      .filter-bar {
        display: flex;
        align-items: center;
        padding: 0 20rpx;
        background-color: white;
        height: 70rpx;
        border-top: 2rpx solid #e4e4e4;
        border-bottom: 2rpx solid #e4e4e4;
        .item {
          display: flex;
          align-items: center;
          justify-content: center;
          flex: 1;
          span {
            font-size: 24rpx;
            color: #666;
          }
          i {
            font-size: 24rpx;
            color: #666;
            margin-left: 10rpx;
          }
        }
        .item:first-child {
          span {
            color: #333;
          }
        }
      }
      .item-list {
        display: flex;
        flex-direction: column;
        .header {
          display: flex;
          align-items: center;
          background-color: white;
          justify-content: space-around;
					margin-top: 20upx;
          .item {
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #F8F8F8;
            flex: 1;
            margin-left: 20rpx;
            padding: 10rpx 0;
            span {
              font-size: 20rpx;
              color: #666;
            }
          }
          .item:last-child {
            margin-right: 20rpx;
          }
        }
				.bottom-line{
					border-bottom: 1rpx solid #F4F4F4;
					padding-bottom: 40rpx;
				}
        .item {
          display: flex;
          background-color: white;
          padding: 40upx 20upx;
					
					// border-bottom: 1rpx solid red;
          .item-l {
            display: flex;
            width: 160rpx;
            height: 120rpx;
            position: relative;
            img {
              width: 160rpx;
              height: 120rpx;
            }
            .tag {
              position: absolute;
              width: 86rpx;
              height: 74rpx;
							top: -4rpx;
							left: -4rpx;
            }
          }
          .item-r {
            margin-left: 20rpx;
            flex-direction: column;
            flex: 1;
            .r-t {
              display: flex;
              flex-direction: column;
              .shop-name {
                font-size: 28rpx;
                color: #333;
                font-weight: bold;
              }
              .t-c {
                display: flex;
                align-items: center;
                margin-top: 10rpx;
                .c-l {
                  display: flex;
                  flex: 1;
                  .l-l {
                    display: flex;
                    i {
                      font-size: 20rpx;
                      color: #F9D173;
                      margin-right: 10rpx;
                    }
                  }
                  .l-m {
                    font-size: 20rpx;
                    color: #333;
                    margin-left: 10rpx;
                  }
                  .l-r {
                    font-size: 20rpx;
                    color: #333;
                    margin-left: 20rpx;
                  }
                }
                .c-r {
                  display: flex;
                  align-items: center;
                  .r-l {
                    font-size: 20rpx;
                    color: #333;
                  }
                  .r-m {
                    width: 2rpx;
                    height: 20rpx;
                    background-color: #ccc;
                    margin: 0 10rpx;
                  }
                  .r-r {
                    font-size: 20rpx;
                    color: #333;
                  }
                }
              }
            }
            .r-m {
              display: flex;
              align-items: center;
              margin-top: 10rpx;
              .m-l {
                font-size: 20rpx;
                color: #333;
              }
              .m-m {
                width: 2rpx;
                height: 20rpx;
                margin: 0 10rpx;
                background-color: #ccc;
              }
              .m-r {
                font-size: 20rpx;
                color: #333;
              }
            }
            .r-b {
              display: flex;
              align-items: center;
              margin-top: 10rpx;
              .b-l {
                color: #09CFB5;
                font-size: 20rpx;
                border: 2rpx solid #09CFB5;
                text-align: center;
                padding: 0 8rpx;
              }
              .b-r {
                @extend .b-l;
                margin-left: 10rpx;
              }
            }
            .activity-c {
              display: flex;
              flex-direction: column;
              .ac-item {
                display: flex;
                align-items: center;
                margin-top: 20rpx;
                .ac {
                  display: flex;
                  align-items: center;
                  .ac-l {
                    width: 30rpx;
                    height: 30rpx;
                    background-size: cover;
                  }
                  .ac-r {
                    color: #666;
                    font-size: 20rpx;
                    margin-left: 10rpx;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
